﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HROReporting.Services.Interfaces;
using HROReporting.Services.Messaging.DocentIncheckingService;
using HROReporting.Model.DocentIncheckingen;
using HROReporting.Infrastructure.UnitOfWork;
using HROReporting.Services.Mapping;
using HROReporting.Model.NFCDevices;

namespace HROReporting.Services.Implementations
{
    public class DocentIncheckingService : IDocentIncheckingService
    {
        private readonly IDocentIncheckingRepository _docentIncheckingRepository;
        private readonly INFCDeviceRepository _nfcDeviceRepository;
        private readonly IUnitOfWork _uow;

        public DocentIncheckingService(IDocentIncheckingRepository docentIncheckingRepository,
                                       INFCDeviceRepository nfcDeviceRepository, IUnitOfWork uow)
        {
            _docentIncheckingRepository = docentIncheckingRepository;
            _nfcDeviceRepository = nfcDeviceRepository;
            _uow = uow;
        }

        public void CreateDocentInchecking(CreateDocentIncheckingRequest request)
        {
            DocentInchecking docentInchecking = new DocentInchecking();

            docentInchecking.DocentCode = request.DocentCode;
            docentInchecking.Datum = DateTime.Now;
            docentInchecking.NFCDeviceId = request.NFCDeviceId;

            _docentIncheckingRepository.Add(docentInchecking);
            _uow.Commit();
        }

        public GetDocentIncheckingByResponse GetDocentIncheckingByDocentCode(GetDocentIncheckingByRequest request)
        {
            GetDocentIncheckingByResponse response = new GetDocentIncheckingByResponse();

            response.DocentInchecking = _docentIncheckingRepository.GetDocentIncheckingByDocentCode(request.DocentCode).ConvertToDocentIncheckingView();

            return response;
        }

        public GetDocentIncheckingByResponse GetDocentIncheckingenByDocentCode(GetDocentIncheckingByRequest request)
        {
            GetDocentIncheckingByResponse response = new GetDocentIncheckingByResponse();

            response.DocentIncheckingen = _docentIncheckingRepository.GetDocentIncheckingenByDocentCode(request.DocentCode).ConvertToDocentIncheckingenView();

            return response;
        }

    }
}
